package cn.yuhh.api.v1.declare;

import cn.yuhh.api.helper.ApiResponse;
import cn.yuhh.api.service.AbstractApiService;
import cn.yuhh.core.annotation.NotNull;
import cn.yuhh.core.domain.DeclareInfo;
import cn.yuhh.core.domain.DeclareLog;
import cn.yuhh.core.type.DeclareStatus;
import com.magic.spring.mongo.IMongoUpdate;
import com.magic.spring.mongo.Mongo;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author ysw
 * @create 2020-02-26-13:55
 * @descreption 办理完成-归档通知相关人员
 **/
@Component("end1.0")
@NotNull(name = {"id"})
public class EndService extends AbstractApiService {
    @Override
    public Map service(Map request) {
        DeclareInfo declareInfo = mongoId(request).findOne(DeclareInfo.class);
        DeclareLog declareLog = Mongo.buildMongo().eq("relId", id(request)).eq("declareStatus", DeclareStatus.handle).findOne(DeclareLog.class);
        mongoId(request).updateFirst(DeclareInfo.class, new IMongoUpdate() {
            @Override
            public void update(Update update) {
                update.set("mainManagerId",declareLog.getMainManagerId());
                update.set("declareStatus",declareInfo.getDeclareStatus().handler(whether(request)));
                update.set("updateAt", System.currentTimeMillis() / 1000);
            }
        });
        //todo 短信通知相关人员
        return ApiResponse.success();
    }
}
